package cn.chainco.cts.idaoImpl;

import java.util.List;

import cn.chainco.cts.idao.IDocTemplateDao;
import cn.chainco.cts.jdo.Company;
import cn.chainco.cts.jdo.DocTemplate;

public class DocTemplateImpl extends GenericHibernateDaoImpl<DocTemplate, Long> implements IDocTemplateDao{

	/**
	 * 文档模板
	 * @param company
	 * @param name
	 * @param status
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DocTemplate> findDocTemp(Company company, String name, Integer status){
		String sql = "select * from cts_doctemplate where 1=1 ";

		if(company != null){
			sql += " and companyId=" + company.getId();
		}

		if((name != null && name != "") && (status == null || (status != null && status != -1))){
			sql += " and name like '%"+name+"%'";
		}

		if(status != null || (status != null && status != -1)){
			sql += " and name='" + name + "'";
		}

		
		if(status != null && status != -1){
			sql += " and status=" + status;
		}

		List<DocTemplate> docTemplist = this.getSession().createSQLQuery(sql).addEntity(DocTemplate.class).list();
		return docTemplist;
	}
}
